package binaryTree.basic;


public class BinaryTreeDepth {
    // 递归求二叉树每个节点的深度
    public static void getDepth(TreeNode root, int depth) {
        if (root == null) {
            return;
        }
        System.out.println(root.val + " depth: " + depth);
        getDepth(root.left, depth + 1);
        getDepth(root.right, depth + 1);

    }
    public static void main(String[] args) {
        // 创建二叉树
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.left = new TreeNode(6);
        root.right.right = new TreeNode(7);
        // 求二叉树每个节点的深度
        getDepth(root, 0);
    }
}
